package com.github.shiqiyue.flow.contol.sample.config;

import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.shiqiyue.flow.contol.FlowControlConfigurer;
import com.github.shiqiyue.flow.contol.dao.FlowControlDao;
import com.github.shiqiyue.flow.contol.dao.InMemoryFlowControlDao;
import com.github.shiqiyue.flow.contol.entity.FlowControlItem;
import com.github.shiqiyue.flow.contol.intercept.action.DefaultFlowControlInterceptAction;
import com.github.shiqiyue.flow.contol.intercept.action.FlowControlInterceptAction;
import com.github.shiqiyue.flow.contol.redis.name.strategy.DefaultRedisKeyNameStrategy;
import com.github.shiqiyue.flow.contol.redis.name.strategy.RedisKeyNameStrategy;

/***
 * 自定义流量控制配置信息
 * 
 * @author wwy
 *
 */
@Component
public class CustomFlowControlConfigurer implements FlowControlConfigurer {
	
	@Autowired
	private RedissonClient redissonClient;
	
	@Override
	public RedissonClient redissonClient() {
		return redissonClient;
	}
	
	@Override
	public FlowControlInterceptAction flowControlInterceptAction() {
		return new DefaultFlowControlInterceptAction();
	}
	
	@Override
	public FlowControlDao flowControlDao() {
		InMemoryFlowControlDao flowControlDao = new InMemoryFlowControlDao();
		flowControlDao.insert(new FlowControlItem("/test/f1/**", 3, 1000L));
		return new InMemoryFlowControlDao();
	}
	
	@Override
	public RedisKeyNameStrategy redisKeyNameStrategy() {
		return new DefaultRedisKeyNameStrategy();
	}
	
}
